#ifndef PLAYSTATE_HPP_
#define PLAYSTATE_HPP_

#include <BulletSoftBody\btSoftBody.h>
#include <LinearMath\btAlignedObjectArray.h>
#include <vector>
#include <string>

#include "gamestate/GameState.hpp"
#include "Character.hpp"
#include "Level.hpp"
#include "EventManager.hpp"

namespace Ogre
{
	class Viewport;
	class SceneManager;
	class Camera;
	class SceneNode;
}

namespace BtOgre
{
	class DebugDrawer;
}

class btBroadphaseInterface;
class btCollisionShape;
//class btOverlappingPairCache;
class btCollisionDispatcher;
class btConstraintSolver;
struct btCollisionAlgorithmCreateFunc;
class btDefaultCollisionConfiguration;

///collisions between two btSoftBody's
class btSoftSoftCollisionAlgorithm;

///collisions between a btSoftBody and a btRigidBody
class btSoftRigidCollisionAlgorithm;
class btSoftRigidDynamicsWorld;
class btDynamicsWorld;
class btRigidBody;
//class btDynamicsWorld;

class PlayState : public GameState
{
	public:
		PlayState(Ogre::Viewport* viewport, OIS::Keyboard* keyboard, OIS::Mouse* mouse)
			: m_Paused(true), m_pViewport(viewport), m_pKeyboard(keyboard), m_pMouse(mouse), m_ShowDebugWorld(false), m_pCharacter(0) {}

		void Init();
		void Run(double);
		void Exit();
		//--------------
		void updateCamera(float deltaTime);
		void updateCameraGoal(float deltaYaw, float deltaPitch, float deltaZoom);
		//--------------
		void Pause();
		void Resume();

		bool keyPressed(const OIS::KeyEvent &keyEventRef);
		bool keyReleased(const OIS::KeyEvent &keyEventRef);

		bool mouseMoved(const OIS::MouseEvent &evt);
		bool mousePressed(const OIS::MouseEvent &evt, OIS::MouseButtonID id);
		bool mouseReleased(const OIS::MouseEvent &evt, OIS::MouseButtonID id);

		void reset();
		
	private:
		void readGameConfiguration(BlobShapeParams& bsp);
		void initCharacter(const BlobShapeParams &bsp);
		void initListeners();

		bool m_Paused;

		// Ogre Cam
		Ogre::SceneNode*						mCameraPivot;		
		Ogre::SceneNode*						mCameraGoal;
		float									mPitch;
		// Bullet Cam
		Ogre::SceneNode*						characterNode;

		Ogre::SceneManager*						m_pScene;
		Ogre::Camera*							m_pCamera;
		Ogre::Viewport*							m_pViewport;
		OIS::Keyboard*							m_pKeyboard;
		OIS::Mouse*								m_pMouse;
		Ogre::SceneNode*						m_pCameraNode;
		Ogre::SceneNode*						m_pCameraYawNode;
		
		btDynamicsWorld*						m_pDynamicsWorld;
		btBroadphaseInterface*					m_pBroadphase;
		btCollisionDispatcher*					m_pDispatcher;
		btConstraintSolver*						m_pSolver;
		btDefaultCollisionConfiguration*		m_pCollisionConfig;
		btSoftBodyWorldInfo						m_sbWorldInfo;
		BtOgre::DebugDrawer*					m_pBtDebugDrawer;

		btAlignedObjectArray<btCollisionShape*> m_CollisionShapes;

		Character*								m_pCharacter;
		Level*									m_pLevelController;
		EventManager							m_EM;

		bool m_ShowDebugWorld;
};

#endif /* PLAYSTATE_HPP_ */
